//
//  AppDelegate.m
//  01-OC微博
//
//  Created by 陈乾 on 15/10/21.
//  Copyright © 2015年 陈乾. All rights reserved.
//

#import "AppDelegate.h"
#import "CQTabBarController.h"
#import "CQNewFeatureController.h"
#import "CQOAuthViewController.h"
#import "CQAccountTool.h"
#import "CQRootTool.h"


#define CQVersionKey @"version"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    
    CQOAuthViewController *oauthVc = [[CQOAuthViewController alloc] init];
    
    self.window.rootViewController = oauthVc;
    
    
    
    if ([CQAccountTool loadAccount]) {
        //有账号  就选择控制器
        [CQRootTool choseNewFeatureViewController:self.window];
        
    }else {
      //没有授权 进入授权界面
        CQOAuthViewController *oauthVc = [[CQOAuthViewController alloc] init];        
        self.window.rootViewController = oauthVc;

    }
    
    //让视图成为主窗口并可视
    [self.window makeKeyAndVisible];
    
    return YES;
}


/**
 *  选择新特性界面
 */
- (void) choseNewFeatureViewController {
    //获取当前的版本号
    NSString *newVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    //获取偏好设置的版本号
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:CQVersionKey];
    //比较
    if ([newVersion isEqualToString:lastVersion]) {
        
        CQTabBarController *tabBarVc = [[CQTabBarController alloc] init];
        self.window.rootViewController = tabBarVc;
        
    }else//有新版本了 需要新特性
    {
        CQNewFeatureController *newFeatureVc = [[CQNewFeatureController alloc] init];
        self.window.rootViewController = newFeatureVc;
        //保存到沙盒
        [[NSUserDefaults standardUserDefaults] setObject:newVersion forKey:CQVersionKey];
    }

}



@end
